package com.chonor.mall.controller;

import com.chonor.mall.common.CommonResult;
import com.chonor.mall.domain.HomeContentResult;
import com.chonor.mall.model.Product;
import com.chonor.mall.model.ProductCategory;
import com.chonor.mall.service.HomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页内容管理Controller
 */
@Controller
@Api(tags = "HomeController", description = "首页内容管理")
@RequestMapping("/home")
public class HomeController {
    @Autowired
    private HomeService homeService;

    @ApiOperation("首页内容页信息展示")
    @RequestMapping(value = "/content", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<HomeContentResult> content() {
        HomeContentResult contentResult = homeService.content();
        return CommonResult.success(contentResult);
    }

    @ApiOperation("分页获取推荐商品")
    @RequestMapping(value = "/recommendProductList", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<Product>> recommendProductList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<Product> productList = homeService.recommendProductList(pageSize, pageNum);
        return CommonResult.success(productList);
    }

    @ApiOperation("获取首页商品分类")
    @RequestMapping(value = "/productCateList/{parentId}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<ProductCategory>> getProductCateList(@PathVariable Long parentId) {
        List<ProductCategory> productCategoryList = homeService.getProductCateList(parentId);
        return CommonResult.success(productCategoryList);
    }

//    @ApiOperation("根据分类获取专题")
//    @RequestMapping(value = "/subjectList", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<List<CmsSubject>> getSubjectList(@RequestParam(required = false) Long cateId,
//                                                         @RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
//                                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
//        List<CmsSubject> subjectList = homeService.getSubjectList(cateId,pageSize,pageNum);
//        return CommonResult.success(subjectList);
//    }

    @ApiOperation("分页获取人气推荐商品")
    @RequestMapping(value = "/hotProductList", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<Product>> hotProductList() {
        List<Product> productList = homeService.hotProductList();
        return CommonResult.success(productList);
    }

//    @ApiOperation("分页获取新品推荐商品")
//    @RequestMapping(value = "/newProductList", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<List<Product>> newProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
//                                                         @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) {
//        List<Product> productList = homeService.newProductList(pageNum,pageSize);
//        return CommonResult.success(productList);
//    }
}
